package ks.client.controllers.requests;

import javax.swing.JFrame;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import ks.client.UserContext;
import ks.client.gui.GMGUI;
import ks.client.lobby.Lobby;
import ks.client.lobby.RoomGUI;
import ks.framework.common.Message;
import ks.framework.interfaces.IProcessMessage;
import ks.managers.table.Table;
import ks.managers.table.TableManager;

/**
 * Parameters for this controller class are received from a server side controller 
 * that is sent a command from the JoinTableClick Controller.
 * 
 * @author szutshi
 * @author Christopher Page
 */
public class ConfirmController implements IProcessMessage {
	Lobby lobby;

	public ConfirmController(Lobby lobby) { 
		this.lobby = lobby;
	}
	
	public boolean process(Message m) {
		System.out.println("Confirming.............");
		Node confirm = m.contents();
		
		if (confirm == null)
			return false;
		
		if (!confirm.getNodeName().equalsIgnoreCase("confirm"))
			return false;
		
		NamedNodeMap nnp = confirm.getAttributes();
		
		Node tableNode = nnp.getNamedItem("table");
		Node playerNode = nnp.getNamedItem("player");
		
		if (tableNode == null)
			return false;
		if (playerNode == null)
			return false;
		
		// The TABLE_NUMBER the PLAYER wants to join
		int table = Integer.parseInt(tableNode.getNodeValue());
		// The PLAYER that wants to join the table
		String player = tableNode.getNodeValue();
		
		//TODO Ask client actor (person who's using it) to confirm player join
		////////////
		System.err.println("ConfirmController: controller is not complete!");
		
		
		return true;
	}
}